<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png?v=5.1.4">


  <link rel="mask-icon" href="/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="数据结构,算法,数据结构与算法,">










<meta name="description" content="每当有人说起数据结构与算法，我都肃然起敬，即便没有听懂也觉得很有道理，未曾意识到作为程序猿数据结构与算法是基石，直到我又下定决心要学好它">
<meta name="keywords" content="数据结构,算法,数据结构与算法">
<meta property="og:type" content="article">
<meta property="og:title" content="数据结构与算法00-缘起">
<meta property="og:url" content="https://sakurayuki.gitee.io/post/a830df26.html">
<meta property="og:site_name" content="Yukiの小居">
<meta property="og:description" content="每当有人说起数据结构与算法，我都肃然起敬，即便没有听懂也觉得很有道理，未曾意识到作为程序猿数据结构与算法是基石，直到我又下定决心要学好它">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-01-07T06:32:18.768Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="数据结构与算法00-缘起">
<meta name="twitter:description" content="每当有人说起数据结构与算法，我都肃然起敬，即便没有听懂也觉得很有道理，未曾意识到作为程序猿数据结构与算法是基石，直到我又下定决心要学好它">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://sakurayuki.gitee.io/post/a830df26.html">





  <title>数据结构与算法00-缘起 | Yukiの小居</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Yukiの小居</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">浮华都市 坚定向前</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://sakurayuki.gitee.io/post/a830df26.html">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Yuki">
      <meta itemprop="description" content="智人发明了语言 智人发明了编程语言">
      <meta itemprop="image" content="/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Yukiの小居">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">数据结构与算法00-缘起</h2>
        

        <div class="post-meta">
          <span class="post-time">
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/数据结构与算法/" itemprop="url" rel="index">
                    <span itemprop="name">数据结构与算法</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/post/a830df26.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="post/a830df26.html" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i> 本文阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                <span title="字数统计">
                  1.6k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                <span title="阅读时长">
                  5
                </span>
              
            </div>
          

          
              <div class="post-description">
                  每当有人说起数据结构与算法，我都肃然起敬，即便没有听懂也觉得很有道理，未曾意识到作为程序猿数据结构与算法是基石，直到我又下定决心要学好它
              </div>
          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>人人都知道数据结构与算法对自己编程生涯的重要性<br>人人都能把它学好并与自己的代码相结合<br>但事实上可能手写冒泡排序都写错了</p>
</blockquote>
<h2 id="往事"><a href="#往事" class="headerlink" title="往事"></a>往事</h2><blockquote>
<p>这不是我第一次下定决心学习数据结构与算法，事实上它就像英语一样，我知道其重要性，却总是学习的时候不得其法，再配上我多动的性格，总是不了了之，再无回想</p>
</blockquote>
<h3 id="第一个算法"><a href="#第一个算法" class="headerlink" title="第一个算法"></a>第一个算法</h3><p>我的入门编程语言是 Java，学 Java 是为了开发 Android。自己当时就到网上找呀，找到了毕向东老师的 Java 入门视频。毕老师的 Java 讲得真的太棒了，在毕老师的指导下，我接触了数据类型、判断和循环，然后接触了一个算法：<strong>选择排序</strong>，当时跟着视频代码很快写完了，运行一下也没问题，可是等到再默写的时候就完全懵了，因为不明白原理，完全无从下手。</p>
<p>那时我知道了算法是一个神奇的东西，不过也仅限于此了，我当时强行记下选择排序的写法，然后继续往后面学，再碰到冒泡排序，一样是强行记住写法。现在我知道这样是毫无用处的，不理解的东西就不是自己的，就像一图书馆的书，摆在那里都不是自己的。</p>
<h3 id="曾经的窘态"><a href="#曾经的窘态" class="headerlink" title="曾经的窘态"></a>曾经的窘态</h3><p>满心期待的学 Java 是为了 Android，然而学校告诉我们学 Android 方向的人太多，让我们重新选择方向，在老师的各种安利下转到了 JavaWeb 方向，然后又没过太久，全班又从 Java 转到了 .NET 方向，命途多舛呐。</p>
<p>那是大二时的校招（别问为什么大二校招，学校就是这样安排的），在学校通过了初试，然后周末到公司机试，记得当时是让写一个冒泡排序，然后机试特别的紧张，紧张到数组都不记得怎么定义了，很心虚的问了一下监考员数组怎么定义，他当时都乐了，告诉我后继续写。过程不顺利，十几分钟内定时间内，经历了死循环、数组越界和无排序效果等问题后，勉强写完了冒泡排序，结果自然是没有结果。</p>
<p>很多人认为手写冒泡排序这样的题目是没有意义的，如果不是亲身经历我也肯定这样认为。</p>
<p>现在看来，<strong>冒泡排序，可以说是菜鸡和菜鸟的分水岭</strong></p>
<h2 id="改变"><a href="#改变" class="headerlink" title="改变"></a>改变</h2><blockquote>
<p>我不想也无法劝说那些无视数据结构与算法重要性的人，有些事情只有自己体会</p>
</blockquote>
<h3 id="系统过载"><a href="#系统过载" class="headerlink" title="系统过载"></a>系统过载</h3><p>其实我所编写的程序，一直就没有经历过很大的数据处理，所以很少有应用和思考数据结构与算法所带来的效益问题。我相信很多人和我一样，处理的数据量很小，所以没机会用，没机会反思和实践，然后继续做着一份无足轻重的事情，恶性循环。</p>
<p>18 年我因为新公司的需求，开始使用 Python 作为主要语言来进行编程，Python 这个语言哪里都好，就是计算效率的确有点弱。在新公司处理数据量也不是很大，几十万上百万的级别，因为不是互联网企业，所以对效率不敏感，就那么几个人用。可我自己受不了呀，一百万不到的数据处理半个小时，于是我尝试寻找出路。</p>
<p>我使用 C API 来做核心的分析功能，可是循环就是循环，C 语言跑得再快，快它个 100 倍，也抵不过多一个 for 循环，直接指数增长。使用 C API 代替 Python 部分代码后，速度的确明显提升了，为此领导还夸赞我技术好，实在是汗颜，明明是自己代码写得烂…</p>
<h3 id="优化提升"><a href="#优化提升" class="headerlink" title="优化提升"></a>优化提升</h3><p>虽然领导满意了，可我还是心虚，我想到了数据结构与算法方面的优化，于是开始找资料学习研究。资料很多，但却找不到类似的案例，没办法只能从头学起，把数据结构与算法方面的东西都捡起来，就在这时极客时间正好推出了<a href="https://time.geekbang.org/column/126" target="_blank" rel="noopener">《数据结构与算法之美》</a>这个专栏，我甚至怀疑是不是乔布斯看我太菜了派人来拯救我了(误)。反正赶紧订阅然后坐等更新了，我可以说这 68 块钱可能是我回报率最高的一次投资，因为作者王争用通俗易懂的语言让我明白和记住了时间复杂度这个概念，解决了我多年未决的疑惑。</p>
<p>但是我看到十几章的时候，又被琐事耽搁，等到回过头来，专栏都更新到 43 章了，真的汗颜。我认为自己最应该提升的，并非某个专业技能，而是提升学习能力，吸收力暂且不说，就这个持久力，有很大的空间需要进步。</p>
<h2 id="前路"><a href="#前路" class="headerlink" title="前路"></a>前路</h2><blockquote>
<p>我希望我能坚持走下去，我想我能继续走下去</p>
</blockquote>
<h3 id="许诺"><a href="#许诺" class="headerlink" title="许诺"></a>许诺</h3><p>我不想事事半途而废功亏一篑，这个<strong>数据结构与算法</strong>系列，我会一直更新下去，其中大部分内容来自于对王争所写专栏的理解，照搬是不可能照搬的，照搬我就凉了，所以这就逼迫我去消化思考，得出自己的理解，倒也是个很妙的限制。</p>
<p>做个承诺吧，一周至少更新一篇，这样算的话一年也有五六十篇了，我觉得海星，这个承诺写给自己。</p>
<h3 id="框架"><a href="#框架" class="headerlink" title="框架"></a>框架</h3><p>这个系列我不想太术语化，哦当然，该术语化的地方还是不能少，只是我希望能像聊天一样表现出我的个人风格，也许每个人的感知不同，但至少我自己能够回过头来看到那个时候真实的我，写的每个字都是我的血肉和骨架。</p>
<p>所以后续文章保证知识尽可能少的错误，错别字尽可能没有。语言风格可能偏向于日常聊天，多少有几句俏皮话，毕竟人生啊，快乐就完事了。</p>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">

  
    <li class="post-copyright-author">
      <strong>文章标题：</strong>
      数据结构与算法00-缘起
    </li>
  
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    Yuki
  </li>
  
    <li class="post-copyright-author">
      <strong>发布时间：</strong>
      <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-06T21:29:28+08:00">
        2019年01月06日 21:29
      </time>
    </li>
  
  
    <li class="post-copyright-author">
      <strong>更新时间：</strong>
      <time title="更新于" itemprop="dateModified" datetime="2019-01-07T14:32:18+08:00">
        2019年01月07日 14:32
      </time>
    </li>
  
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://sakurayuki.gitee.io/post/a830df26.html" title="数据结构与算法00-缘起">https://sakurayuki.gitee.io/post/a830df26.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    <i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/数据结构/" rel="tag"><i class="fa fa-tag"></i> 数据结构</a>
          
            <a href="/tags/算法/" rel="tag"><i class="fa fa-tag"></i> 算法</a>
          
            <a href="/tags/数据结构与算法/" rel="tag"><i class="fa fa-tag"></i> 数据结构与算法</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/post/21751723.html" rel="next" title="公历年初 农历年末">
                <i class="fa fa-chevron-left"></i> 公历年初 农历年末
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/post/5902f98d.html" rel="prev" title="数据结构与算法01-时间复杂度">
                数据结构与算法01-时间复杂度 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/avatar.gif" alt="Yuki">
            
              <p class="site-author-name" itemprop="name">Yuki</p>
              <p class="site-description motion-element" itemprop="description">智人发明了语言 智人发明了编程语言</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="mailto:yuki1015@live.com" target="_blank" title="Email">
                      
                        <i class="fa fa-fw fa-envelope"></i>Email</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sakurayuki" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/YukiSakura_K" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/yuki951015" target="_blank" title="Weibo">
                      
                        <i class="fa fa-fw fa-weibo"></i>Weibo</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/yuki_sakura" target="_blank" title="Zhihu">
                      
                        <i class="fa fa-fw fa-quora"></i>Zhihu</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#往事"><span class="nav-number">1.</span> <span class="nav-text">往事</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#第一个算法"><span class="nav-number">1.1.</span> <span class="nav-text">第一个算法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#曾经的窘态"><span class="nav-number">1.2.</span> <span class="nav-text">曾经的窘态</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#改变"><span class="nav-number">2.</span> <span class="nav-text">改变</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#系统过载"><span class="nav-number">2.1.</span> <span class="nav-text">系统过载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#优化提升"><span class="nav-number">2.2.</span> <span class="nav-text">优化提升</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#前路"><span class="nav-number">3.</span> <span class="nav-text">前路</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#许诺"><span class="nav-number">3.1.</span> <span class="nav-text">许诺</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#框架"><span class="nav-number">3.2.</span> <span class="nav-text">框架</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Yuki</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-pencil"></i>
    </span>
    
    <span title="博客文字总数">5.5k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a></div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-eercast"></i> 总访客
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i> 总访问
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>



<script>
  	var _mtac = {};
  	(function() {
  		var mta = document.createElement("script");
  		mta.src = "https://pingjs.qq.com/h5/stats.js?v2.0.4";
  		mta.setAttribute("name", "MTAH5");
  		mta.setAttribute("sid", "500665537");

  		var s = document.getElementsByTagName("script")[0];
  		s.parentNode.insertBefore(mta, s);
  	})();
</script>



  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=66153766";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://sakurayuki-gitee-io.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://sakurayuki.gitee.io/post/a830df26.html';
          this.page.identifier = 'post/a830df26.html';
          this.page.title = '数据结构与算法00-缘起';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://sakurayuki-gitee-io.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  

















  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>

   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;"></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/src/fireworks.js"></script>

</html>
